import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default new Vuex.Store({
    state: {
        HOST: process.env.NODE_ENV === 'production' ? 'http://121.89.172.98:8888' : 'http://localhost:8888',
        isPlay: false,//默认是不播放的
        url: '',//歌曲地址
        id: ''//歌曲id
    },
    //取值
    getters: {
        isPlay: state => state.isPlay,
        url: state => state.url,
        id: state => state.id,
    },
    //设置值
    mutations: {
        setIsPlay: (state, isPlay) => {
            state.isPlay = isPlay
        },
        setUrl: (state, url) => {
            if (url.startsWith('http')) {
                console.log(url, '不添加http')
                state.url = url
            } else {
                console.log(url, '添加http')
                state.url = state.HOST + url
            }
        },
        setId: (state, id) => {
            state.id = id
        },
    },
    actions: {},
    modules: {}
})
